package com.chris.homecare.screens
{
	import com.chris.homecare.components.BreadcrumbComponenet;
	import com.chris.homecare.components.BulletHeadingComp;
	import com.chris.homecare.components.HeaderComponent;
	import com.chris.homecare.data.DataUtil;
	import com.chris.homecare.data.FetchRemoteData;
	import com.chris.homecare.data.Update;
	import com.chris.homecare.utils.CommonUtils;
	import com.chris.homecare.utils.ScreenNames;
	
	import flash.filesystem.File;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	import feathers.controls.ImageLoader;
	import feathers.controls.Label;
	import feathers.controls.Screen;
	import feathers.controls.ScrollContainer;
	import feathers.controls.text.TextFieldTextRenderer;
	import feathers.core.ITextRenderer;
	import feathers.layout.VerticalLayout;
	
	import starling.display.Quad;
	
	public class UpdateScreen extends Screen
	{
		private var updateObject:Update;
		private var headerComp:HeaderComponent;
		private var breadcrumbComp:BreadcrumbComponenet;
		private var scrollContainer:ScrollContainer;

		private var gapingQuad1:Quad;

		private var contentLabel:Label;

		private var updateImage:ImageLoader;
		private var bulletHeadingComp:BulletHeadingComp;
		
		public function UpdateScreen()
		{
			super();
			
			updateObject = DataUtil.getUpdateForId(FetchRemoteData.choosenUpdateId);
		}
		
		override protected function initialize():void
		{
			CommonUtils.previousScreen = ScreenNames.UPDATES_LIST_SCREEN;
			
			var layout:VerticalLayout = new VerticalLayout();
			this.layout = layout;
			
			headerComp = new HeaderComponent();
			addChild(headerComp);
			
			breadcrumbComp = new BreadcrumbComponenet("Updates");
			addChild(breadcrumbComp);
			
			bulletHeadingComp = new BulletHeadingComp(updateObject.headingText);
			addChild(bulletHeadingComp);
			
			gapingQuad1 = new Quad(20,20*CommonUtils.scaleValue, 0xFFFFFF);
			addChild(gapingQuad1);
			
			scrollContainer = new ScrollContainer();
			var containerLayout:VerticalLayout = new VerticalLayout();
			containerLayout.horizontalAlign = VerticalLayout.HORIZONTAL_ALIGN_CENTER;
			scrollContainer.layout = containerLayout;
			addChild(scrollContainer);
			
			
			/*var headingLabel:Label = new Label();
			headingLabel.nameList.add("updates-heading-lbl");
			headingLabel.text = updateObject.headingText;
			scrollContainer.addChild(headingLabel);*/
			
			var gapingQuad2:Quad = new Quad(20,20*CommonUtils.scaleValue, 0xFFFFFF);
			scrollContainer.addChild(gapingQuad2);
			
			updateImage = new ImageLoader();
			updateImage.source = File.applicationStorageDirectory.resolvePath(updateObject.imageUrl).url;
			scrollContainer.addChild(updateImage);
			
			var gapingQuad3:Quad = new Quad(20,20*CommonUtils.scaleValue, 0xFFFFFF);
			scrollContainer.addChild(gapingQuad3);
			
			contentLabel = new Label();
			contentLabel.textRendererFactory = function():ITextRenderer
			{
				var textRenderer:TextFieldTextRenderer = new TextFieldTextRenderer();
				textRenderer.textFormat = new TextFormat("Helvetica", 26*CommonUtils.scaleValue, 0x000000, null, null, null, null, null, TextFormatAlign.JUSTIFY);
				textRenderer.isHTML = true;
				return textRenderer;
			}
			contentLabel.textRendererProperties.wordWrap = true;
			contentLabel.text = updateObject.description;
			scrollContainer.addChild(contentLabel);
			
			super.initialize();
		}
		
		override protected function draw():void
		{
			super.draw();
			
			var stageWidth:int = stage.stageWidth;
			var stageHeight:int = stage.stageHeight;
			
			scrollContainer.height = stageHeight - scrollContainer.y - 20*CommonUtils.scaleValue;
			scrollContainer.width = stageWidth;
			updateImage.width = contentLabel.width = stageWidth - 40*CommonUtils.scaleValue;

		}
		
		
	}
}